home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / BBS / MUBBS / MUBBS etc.cpt / Module Source / E-mail / SaveEmail.c < prev    next >
Text File  |  1991-11-21  |  4KB  |  144 lines

  1. /* *********************************************************************************
  2.      
  3.       MODULE:        SaveEmail Module
  4.       
  5.      DESCRIPTION:    This SaveEmail Module is a simple module for MUBBS, the
  6.                      Multi-User Bulliten Board System Software.
  7.                      
  8.      AUTHOR:        Noam Freedman
  9.      
  10.      Copyright © 1990 by Noam Freedman. Portions are also Copyright Symantec Corp.
  11.  
  12.      This program source code and it's compiled version IS NOT IN THE
  13.      PUBLIC DOMAIN ! Please read the "COPYRIGHT NOTICE / NMF" file for details
  14.      regarding use of this program source code and it's compiled version.
  15.      
  16.      Revision History:
  17.      ============================================================
  18.       8/30/91 - Started programming
  19.      11/ 4/91 - Edited for release
  20.      ============================================================
  21.      
  22.  
  23.     ******************************************************************************** */
  24.  
  25.  
  26. #define        INMAIN
  27.  
  28. #include    "Email.h"
  29. #include    "MUBBS Module.h"
  30. #include    <SetUpA4.h>
  31.                 
  32. pascal void main (mode1,G1,P1)
  33.        int mode1;
  34.        struct GS *G1;
  35.        Ptr P1;  
  36. {
  37. Handle temph;
  38. float version = 0.5; /* what version of MUBBS you are compatable with IE: .5 and above */
  39. RememberA0(); SetUpA4(); /* This sets up the A4 register to access our globals */
  40. asm { _RecoverHandle }; asm {move.l a0,temph}; HLock(temph); /* locks our module, do this ! */
  41.  
  42. G=G1; /* This MUST be the first thing you do in main only, it sets up the struct globals */
  43. mode[u]=mode1; /* set up our mode so that you can read it anywhere */
  44.  
  45. switch (mode[u]) { /* any un-handled modes return error from this module */
  46.     case 3:
  47.         saveemail(P1);/* mode 3 because we are passing a user pointer */
  48.         G->moduleresult=0;
  49.         break;
  50.     case 98:
  51.         versionck(version); /* just return after this call, don't modify anything */
  52.         break;        
  53.     case 0:
  54.         strcpy (G->programmer,"Noam Freedman"); /* show the programmer's name up to 20 chars*/
  55.         G->moduleresult=0; /* this was also a init call if we need close call put 99 here */
  56.         break;
  57.     default:
  58.         G->moduleresult=1; /* return bad code */
  59.     };
  60.  
  61. HUnlock(temph); /* unlocks this module, do this ! */
  62. RestoreA4(); /* call this when you are all done */
  63. }
  64.  
  65.  
  66. saveemail(S)
  67. struct EnterStruct *S;
  68. {
  69. char PAD[100]; /* padding to cover a glitch */
  70. struct MsgStruct MsgInfo;
  71. struct FixStruct fixinfo;
  72. FILE *fp_headers, *fp_text;
  73. int a,i,num;
  74. long int temp,tempa;
  75.  
  76. if (!G->online[u]) { num = 2;goto byebye; } /* do this check so we can log out if hang up */
  77.  
  78. if (S->result==0) { /* if there's no "enter" made then quit */
  79.     num=1;
  80.     goto byebye;
  81.     }
  82.  
  83.  
  84. strcpy(MsgInfo.FromUser,S->FromUser);
  85. strcpy(MsgInfo.ToUser,S->ToUser);
  86. strcpy(MsgInfo.title,S->title);
  87. strcpy(MsgInfo.NetAddress,S->NetAddress);
  88. strcpy(MsgInfo.temp,"NOAM");
  89. MsgInfo.status = UNREAD;
  90. getdatetime(MsgInfo.DateSent);                                
  91. if ( (fp_headers = fopen(":msgs:email.headers","a")) == NULL )
  92.     {
  93.     send("]]Can't open the file: %s]",":msgs:email.headers");
  94.     send("]Your e-mail could not be saved.]");
  95.     pause();
  96.     num = 3;
  97.     goto byebye;
  98.     }
  99. else
  100.     {
  101.     if ( (fp_text = fopen(":msgs:email.data","a")) == NULL )
  102.         {
  103.         send("]]Can't open the file: %s]",":msgs:email.data");
  104.         send("Your e-mail could not be saved.]");
  105.         pause();
  106.         num = 3;
  107.         goto byebye;
  108.         }
  109.     else
  110.         {
  111.         temp = ftell(fp_text);
  112.         for (i=0;i<=S->numlines && i < 49;i++)
  113.             {
  114.             for (a = 0;a<=79;a++)
  115.                 {
  116.                 if (S->emailtext[i][a] != '\0')
  117.                     fputc(S->emailtext[i][a],fp_text);
  118.                 else
  119.                     {
  120.                     a = 81;
  121.                     fputc('\n',fp_text);
  122.                     }
  123.                 }
  124.             }
  125.         fputc('~',fp_text); /* mark the end */
  126.         tempa = ftell(fp_text);
  127.         fixinfo.offset= temp;
  128.         fixinfo.length= tempa - temp;
  129.         fwrite( &fixinfo.offset, sizeof(fixinfo), 1, fp_text); /* write the data incase of fix */
  130.         tempa = ftell(fp_text);
  131.         fclose(fp_text);
  132.         MsgInfo.offset = temp;
  133.         MsgInfo.length = tempa - temp;
  134.         S->offset = temp;
  135.         S->length = tempa - temp;
  136.         fwrite( &MsgInfo.FromUser[0], sizeof(MsgInfo), 1, fp_headers);
  137.         fclose(fp_headers);
  138.         send("]Email sent to \"%s\"]",MsgInfo.ToUser);
  139.         }
  140.     }
  141. byebye:
  142. S->result = num;
  143. }                
  144.